package com.ruoyi.project.poem.poemaudiorecom.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.poem.poemaudiorecom.domain.PoemAudioRecom;
import com.ruoyi.project.poem.poemaudiorecom.service.IPoemAudioRecomService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 读诗审核Controller
 *
 * @author shixiangwen
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/poem/poemaudiorecom")
public class PoemAudioRecomController extends BaseController {
    private String prefix = "poem/poemaudiorecom";

    @Autowired
    private IPoemAudioRecomService poemAudioRecomService;

    @RequiresPermissions("poem:poemaudiorecom:view")
    @GetMapping()
    public String poemaudiorecom() {
        return prefix + "/poemaudiorecom";
    }

    /**
     * 查询读诗审核列表
     */
    @RequiresPermissions("poem:poemaudiorecom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PoemAudioRecom poemAudioRecom) {
        startPage();
        List<PoemAudioRecom> list = poemAudioRecomService.selectPoemAudioRecomList(poemAudioRecom);
        return getDataTable(list);
    }

    /**
     * 导出读诗审核列表
     */
    @RequiresPermissions("poem:poemaudiorecom:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PoemAudioRecom poemAudioRecom) {
        List<PoemAudioRecom> list = poemAudioRecomService.selectPoemAudioRecomList(poemAudioRecom);
        ExcelUtil<PoemAudioRecom> util = new ExcelUtil<PoemAudioRecom>(PoemAudioRecom.class);
        return util.exportExcel(list, "poemaudiorecom");
    }

    /**
     * 新增读诗审核
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存读诗审核
     */
    @RequiresPermissions("poem:poemaudiorecom:add")
    @Log(title = "读诗审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PoemAudioRecom poemAudioRecom) {
        return toAjax(poemAudioRecomService.insertPoemAudioRecom(poemAudioRecom));
    }

    /**
     * 修改读诗审核
     */
    @GetMapping("/edit/{articleId}")
    public String edit(@PathVariable("articleId") String articleId, ModelMap mmap) {
        PoemAudioRecom poemAudioRecom = poemAudioRecomService.selectPoemAudioRecomById(articleId);
        mmap.put("poemAudioRecom", poemAudioRecom);
        return prefix + "/edit";
    }

    /**
     * 修改保存读诗审核
     */
    @RequiresPermissions("poem:poemaudiorecom:edit")
    @Log(title = "读诗审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PoemAudioRecom poemAudioRecom) {
        return toAjax(poemAudioRecomService.updatePoemAudioRecom(poemAudioRecom));
    }

    @RequiresPermissions("dict:poemaudiorecom:edit")
    @Log(title = "读诗审核", businessType = BusinessType.UPDATE)
    @PostMapping("/approve")
    @ResponseBody
    public AjaxResult approve(String id, Integer status) {
        return toAjax(poemAudioRecomService.approve(id, status));
    }


    /**
     * 删除读诗审核
     */
    @RequiresPermissions("poem:poemaudiorecom:remove")
    @Log(title = "读诗审核", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(poemAudioRecomService.deletePoemAudioRecomByIds(ids));
    }
}
